package com.hushan.elevator.controller;

import com.hushan.elevator.model.Department;
import com.hushan.elevator.model.DeviceInfo;
import com.hushan.elevator.model.User;
import com.hushan.elevator.security.SecurityUtils;
import com.hushan.elevator.service.*;
import com.hushan.elevator.utils.Result;
import com.hushan.elevator.utils.ResultCode;
import com.hushan.elevator.vo.MonitorDtree;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/monitor")
public class MonitorController {
    private final RiskRecordService riskService;
    private final DeptService deptService;
    private final MntPersonService mntPersonService;
    private final DeviceInfoService deviceInfoService;
    private final UserService userService;
    private final StaticsService staticsService;
    public MonitorController(RiskRecordService riskService, DeptService deptService, MntPersonService mntPersonService, DeviceInfoService deviceInfoService, UserService userService, StaticsService staticsService) {
        this.riskService = riskService;
        this.deptService = deptService;
        this.mntPersonService = mntPersonService;
        this.deviceInfoService = deviceInfoService;
        this.userService = userService;
        this.staticsService = staticsService;
    }

    @Operation(summary = "获取监控页面左侧部门导航栏", description = "获取监控页面左侧部门导航栏")
    @GetMapping("/dtree")
    public Result getDtree() {
        User requester = SecurityUtils.getUser();
        Department rootDept = deptService.findDeptByUserId(requester.getUserId());
        MonitorDtree monitorTree = staticsService.getMonitorTree(rootDept.getDeptId());
        return new Result(ResultCode.SUCCESS,monitorTree);
    }

    @Operation(summary = "获取监控页面左侧部门导航栏", description = "获取监控页面左侧部门导航栏")
    @GetMapping("/dtree/{id}")
    public Result getDtreeById(@PathVariable("id") int id) {
        MonitorDtree monitorTree = staticsService.getMonitorTree(id);

        return new Result(ResultCode.SUCCESS,monitorTree);
    }

    @Operation(summary = "监控页面风险统计", description = "监控页面风险统计")
    @GetMapping("/risk/device/{devId}")
    public Result getMonitorRiskStatics(@PathVariable("devId") int devId) {

        return new Result(ResultCode.SUCCESS, staticsService.getMonitorStaticsByDevice(devId));
    }
}
